<!DOCTYPE html>
          <head>
        <meta charset="utf-8">
            
            <title>
                「macOS」macOS安装Python | ttdevs
            </title>
            <meta content="width=device-width, initial-scale=1" name="viewport">
            <meta name="theme-color" content="#4184f3">
            
            
            <link href="/favicon.ico" rel="icon"/>
            

            <link rel="stylesheet" href="/css/highlight.light.css">
            <link rel="stylesheet" href="/css/prism-customize.css">
            <link rel="stylesheet" href="/css/nav-icon.css">
            <link rel="stylesheet" href="/css/waves.min.css">
            <link rel="stylesheet" href="/css/jquery.tocify.css">
            <link rel="stylesheet" href="/css/main.css">
            <link rel="stylesheet" href="/css/nav-indicator.css">
            
  

  
  <!-- 谷歌统计 -->
  <script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-97465173-1', 'auto');
    ga('send', 'pageview');

  </script>
  
            </meta>
        </meta>
    </head>

    <body>
        <header>
            <!-- cover image or sth. -->
        </header>
        <div id="main" class="m-scene">
            
<div class="nav-wrapper">

    <div class="container">
        <nav>
            <div class="logo wave">
                <a href="/" id="logo">
                    ttdevs
                </a>
            </div>
            <div class="nav-toggle-icon" >
                <div class="material-hamburger">
                    <span>
                    </span>
                    <span>
                    </span>
                    <span>
                    </span>
                </div>
            </div>
            <div class="menu-wrapper">
                <div class="nav-indicator">
                </div>
                <ul class="menus">
                    
                     
                        <li>
                            <a class="wave " href="/">
                                首页
                            </a>
                        </li>
                     
                        <li>
                            <a class="wave " href="/archives">
                                归档
                            </a>
                        </li>
                     
                        <li>
                            <a class="wave " href="/about">
                                关于
                            </a>
                        </li>
                     
                    
                   
                </ul>
            </div>
        </nav>
    </div>
</div>
            <div class="container content">
                <div class="scene_element scene_element--fadein">
                    <div class="row">
    <div class="main">
        <article>
          
          <header class="post-header with-cover" style="background-image:url('/1970/01/01/[macOS]macOS安装Python/cover.jpg')" >
          
          </header>
          <h1 class="post-title">「macOS」macOS安装Python</h1>

          <section class="post-info">
            <span class="post-date">1970/01/01</span>
            
            <span class="post-category">
                <a class="article-category-link" href="/categories/技术/">技术</a>
            </span>
            
            
            <span class="post-tags">
              <ul class="post-tag-list"><li class="post-tag-list-item"><a class="post-tag-list-link" href="/tags/macOS/">macOS</a></li></ul>
            </span>
            
          </section>

          <section class="post-content">
            <h2 id="0x00-为什么要装-Bi"><a href="/1970/01/01/[macOS]macOS安装Python/#0x00-为什么要装-Bi" class="headerlink" title="0x00 为什么要装(Bi)"></a>0x00 为什么要装(Bi)</h2><p>装逼遭雷劈。</p>
<p>上一篇介绍了重装macOS的方法。为什么会有上一篇？说到底就一个字：跑 python web 应用出问题了。把macOS从旧版本升级到新版本 10.12，之前跑的好好的web应用现在各种问题，所以，重装吧。然并卵，重装后问题依旧 😢，比如：</p>
<p><code>ImportError: No module named &#39;_sqlite3&#39;</code><br><code>ImportError: No module named &#39;pysqlite2&#39;</code></p>
<p>等等一堆问题。好吧，废话说多了，这里介绍下该怎么办。</p>
<h2 id="0x01-安装"><a href="/1970/01/01/[macOS]macOS安装Python/#0x01-安装" class="headerlink" title="0x01 安装"></a>0x01 安装</h2><p>情况是这样的，全新安装macOS，同时升级 xcode 到最新版8 (8A218a)，使用 homebrew 安装 python3 ：</p>
<p><code>brew install python3</code></p>
<p>装好之后还是各种model找不到，缺少很多东西，尝试了各种方法，依然无法解决。</p>
<p>在反复重装 python3 的时候，看到这样一个提示：<code>xcode-select --install</code>。虽然不知道这个鬼东西是干嘛，但是确定一点，之前我有安装过。所以，就在命令行执行了一下，然后再重新安装 python3，他 就，就，就 可以了……</p>
<h2 id="0x02-Command-Line-Tools"><a href="/1970/01/01/[macOS]macOS安装Python/#0x02-Command-Line-Tools" class="headerlink" title="0x02 Command Line Tools"></a>0x02 Command Line Tools</h2><p><code>xcode-select --install</code> 这条命令是的作用是安装 <code>Command Line Tools</code>。找了半天，没看到哪有详细的介绍，在<a href="https://developer.apple.com/library/prerelease/content/technotes/tn2339/_index.html#//apple_ref/doc/uid/DTS40014588-CH1-WHAT_IS_THE_COMMAND_LINE_TOOLS_PACKAGE_" target="_blank" rel="external">这里</a>看到一个简短的介绍：</p>
<blockquote>
<p>The Command Line Tools Package is a small self-contained package available for download separately from Xcode and that allows you to do command line development in OS X. It consists of two components: OS X SDK and command-line tools such as Clang, which are installed in /usr/bin.</p>
</blockquote>
<p>简单来说，应该就是一套工具集合。他会被安装在下面两个位置：</p>
<p><code>/Library/Developer/CommandLineTools/usr/bin</code><br><code>/usr/bin</code></p>
<p>在这里你会看到一堆常见的命令。看到这些之后，恍然大悟，homebrew好像是下的python3的源码，然后本地编译安装的。如果缺少了这些命令，可能就会出错。</p>
<p>好了，终于可以愉快的使用 python 了。</p>
<hr>
<p><img src="https://raw.githubusercontent.com/ttdevs/ttdevs.github.io/common/images/logo.png" alt="Create by ttdevs"></p>

          </section>
        </article>
        

       
        <div class="pager">
          
            <a class="post-prev pager-item" href="/1970/01/01/[WebSocket]使用Websocket实现消息推送(上)/" >
              <strong class="article-nav-caption">上一篇</strong>
              <p class="post-nav-title">「WebSocket」使用Websocket实现消息推送(上)</p>
            </a>
          
          
            <a class="post-next pager-item" href="/1970/01/01/[玩转树莓派]0x00欢迎来到树莓派的世界/">
              <strong class="article-nav-caption">下一篇</strong>
              <p class="post-nav-title">「玩转树莓派」0x00欢迎来到树莓派的世界</p>
            </a>
          
        </div>
        

         <!-- comments -->
        <div class="comment-section">
  
    


</div>

    </div>
    
    <aside>
        <div id="toc">
        </div>
    </aside>
    
</div>

                </div>
            </div>
        </div>
        <footer class="footer">
    <p>由<a href="http://hexo.io/" target="_blank">Hexo</a>强力驱动，搭载<a href="https://github.com/wayou/hexo-theme-gstyle">gstyle</a>主题</p>
    <p>
        &copy; 2017 ttdevs
    </p>
</footer>
<script src="/lib/jquery.js"></script>
<script src="/lib/waves.js"></script>
<script src="/lib/jquery-ui.js"></script>
<script src="/lib/jquery.tocify.js"></script>
<script src="/js/main.js"></script>

    </body>
</html>
